package urna;

import java.io.File;
import java.rmi.*;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
	
public class CRV extends UnicastRemoteObject implements InterfaceCRV {
	
	private static final long serialVersionUID = -6497449860140613998L;
	private Registry registry;
	private int port;
	
	public void startRegistry() throws RemoteException {
		registry = java.rmi.registry.LocateRegistry.createRegistry(port);
	}
	
	public void registerObject(String name, Remote remoteObj) throws RemoteException, AlreadyBoundException {
		registry.bind(name, remoteObj);
	}
	
	public CRV(int port) throws RemoteException {
		this.port = port;
        try 
        {
        	startRegistry();
			registerObject("CRV", this);
		}
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }

	}
	
    public static void main(String[] args) {
        try {
        	if (args.length > 0){
        		new CRV(Integer.parseInt(args[0]));
        		System.out.println("Server UP (port = "+args[0]+")");
        	}
        	else System.out.println("Faltan parametros para la inicializacion del CRV. Parametro1=puerto (1099)");
			
		} catch (RemoteException e) {
			System.out.println(e.getMessage());
		}
    }

	public boolean enviarCandidatos(File resultados) throws RemoteException {
		return true;
	}
    
}
